package com.nosweattechnet.placemap;

import com.nosweattechnet.mapmyway.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public abstract class SuperAddItemActivity extends Activity {

	private MapScaler mapscaler;
	private boolean touched=false;
	private boolean onetouch=true;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapscaler=MapScalerHolder.getMapScaler();
        //Gets the Map of the Place from the MapScaler
        PlaceMap pmap=mapscaler.getPlaceMap();
        setContentView(pmap);
        
        //Creates an OnTouchListner
        pmap.setOnTouchListener(new OnTouchListener(){

			public boolean onTouch(View v, MotionEvent event) {
				//Retrieves the x, y and z locations, and then opens the next activity 
				float x=mapscaler.undoXScale(event.getX());
				float y=mapscaler.undoYScale(event.getY());
				float z=1;
				if(!onetouch||!touched){
					onTouchEvent(x,y,z);
				}
				touched=true;
				return true;
			}
        });
    }
    
    abstract protected void onTouchEvent(float x, float y, float z);

	//Standard options menu creation
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_super_add_item, menu);
        return true;
    }
    
    @Override
    public void onPause(){
    	this.setContentView(new View(this));
    	super.onPause();
    }
    
    protected void allowMultiTouch(){
    	onetouch=false;
    }
}
